package com.etlmaster.executor.processors.Table;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.etlmaster.executor.utils.DpExecutorUtils;


/**
 * @author Wugf
 * @date 2016-03-08
 */
public class CreateTableMeta {

	private String xmlId;

	private String tableName;

	private String metaTableName;

	private String dsName;

	private String override;

	private String db2DistributionKey;

	private String extractParam;
	
	
	private String dsType;
	
	private String taskid;
	
	protected Map<String,Object> variables=new HashMap<String,Object>();

	public CreateTableMeta(String tableName,String xmlId,String dsType,String taskid,String override){
		this.tableName=tableName;
		this.xmlId=xmlId;
		this.taskid=taskid;
		this.dsType=dsType;
		this.override=override;
	}
	public void setDb2DistributionKey(String db2DistributionKey) {
		this.db2DistributionKey = db2DistributionKey;
	}

	protected String tbsSpace;

	protected String indexSpace; // 增加索引空间

	protected String hiveDelimited = "\\t";

	protected String hivePartitionKey;

	protected String hiveStoreType = "textfile";

	protected String hiveLocation;

	protected List<Map<String, Object>> columns;

	protected String schemaName;

	protected String userName;

	protected String password;

	private String creater;

	private String eff_date;


	public String getXmlId() {
		return xmlId;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getMetaTableName() {
		return variableSubstitution(metaTableName);
	}

	public String getDsName() {
		return variableSubstitution(dsName);
	}

	public String getOverride() {
		return override;
	}

	public String getDb2DistributionKey() {
		return db2DistributionKey;
	}

	public String getTbsSpace() {
		return tbsSpace;
	}

	public String getHiveDelimited() {
		return hiveDelimited;
	}

	public String getHivePartitionKey() {
		return hivePartitionKey;
	}

	void setHivePartitionKey(String hivePartitionKey) {
		this.hivePartitionKey = hivePartitionKey;
	}

	public String getHiveStoreType() {
		return hiveStoreType;
	}

	public String getHiveLocation() {
		return hiveLocation;
	}

	public List<Map<String, Object>> getColumns() {
		return columns;
	}

	public void setColumns(List<Map<String, Object>> columns) {
		this.columns = columns;
	}

	public String getSchemaName() {
		return schemaName;
	}

	public String getUserName() {
		return userName;
	}

	public String getPassword() {
		return password;
	}

	public void setXmlId(String xmlId) {
		this.xmlId = xmlId;
	}

	public void setMetaTableName(String metaTableName) {
		this.metaTableName = metaTableName;
	}

	public void setDsName(String dsName) {
		this.dsName = dsName;
	}

	public void setOverride(String override) {
		this.override = override;
	}

	public void setTbsSpace(String tbsSpace) {
		this.tbsSpace = tbsSpace;
	}

	public void setHiveDelimited(String hiveDelimited) {
		this.hiveDelimited = hiveDelimited;
	}

	public void setHiveStoreType(String hiveStoreType) {
		this.hiveStoreType = hiveStoreType;
	}

	public void setHiveLocation(String hiveLocation) {
		this.hiveLocation = hiveLocation;
	}

	public void setSchemaName(String schemaName) {
		this.schemaName = schemaName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getIndexSpace() {
		return indexSpace;
	}

	public void setIndexSpace(String indexSpace) {
		this.indexSpace = indexSpace;
	}

	public String getCreater() {
		if (creater != null)
			return creater;
		else {
			return "";
		}
	}

	public void setCreater(String creater) {
		this.creater = creater;
	}

	public String getEff_date() {
		if (eff_date != null)
			return eff_date;
		else {
			return "";
		}
	}

	public Map<String, String> getExtraParam() {
		if (this.extractParam != null && this.extractParam.length() > 0) {
			String []extras=this.extractParam.split(";");
			Map<String,String> map=new HashMap<String,String>();
			for(int i=0;i<extras.length;i++){
				map.put("extra"+i, extras[i]);
			}
			return map;
		} else {
			return null;
		}
	}

	public void setEff_date(String eff_date) {
		this.eff_date = eff_date;
	}

	public String getExtractParam() {
		return extractParam;
	}

	public void setExtractParam(String extractParam) {
		this.extractParam = extractParam;
	}


	public String variableSubstitution(String text){
		return variableSubstitution(text, null);
	}
	
	public String variableSubstitution(String text,Map<String,Object> appendData){
		if(appendData!=null && appendData.size()>0){
			
			return DpExecutorUtils.variableSubstitution(text,appendData);
		}else{
			return text;
		}
		
	}

	public String getDsType() {
		return dsType;
	}

	public void setDsType(String dsType) {
		this.dsType = dsType;
	}

	public String getTaskid() {
		return taskid;
	}

	public void setTaskid(String taskid) {
		this.taskid = taskid;
	}

}
